var basePath = $("#basePath").val();
/*============================试题提交前进行权限验证============================================*/
function  volidateAuthorizationForSubmit() {
    var flag = true;
    $.ajax({
        url: basePath.value+"/examination/volidateAuthorizationForSubmit",
        type: "GET",
        dataType: "json",
        success: function (obj) {
            if (obj.code != null && obj.code == 200) {
                layer.msg(obj.msg, {icon: 5, time: 2000});
                flag = false;
            }
        }
    });
    return flag;
}
/*============================试题提交前进行权限验证============================================*/


/***************************************验证总分与单项和分数是否相等****************************************/
/*问答题-腧穴*/
function  validateIsEqualEachTermAndTotalScoreWendaAcupoint() {
    var validateTotalScore = false;
    var totalScore=$("#form-wenda").find("input[name='totalScore']").val();
    var location1Score=$("#form-wenda").find("input[name='location1Score']").val();
    var location2Score=$("#form-wenda").find("input[name='location2Score']").val();
    var location3Score=$("#form-wenda").find("input[name='location3Score']").val();
    var meridianScore=$("#form-wenda").find("input[name='meridianScore']").val();
    var mayorCure1Score=$("#form-wenda").find("input[name='mayorCure1Score']").val();
    var mayorCure2Score=$("#form-wenda").find("input[name='mayorCure2Score']").val();
    var mayorCure3Score=$("#form-wenda").find("input[name='mayorCure3Score']").val();
    var mayorCure4Score=$("#form-wenda").find("input[name='mayorCure4Score']").val();
    var mayorCure5Score=$("#form-wenda").find("input[name='mayorCure5Score']").val();
    var mayorCure6Score=$("#form-wenda").find("input[name='mayorCure6Score']").val();
    var mayorCure7Score=$("#form-wenda").find("input[name='mayorCure7Score']").val();
    var mayorCure8Score=$("#form-wenda").find("input[name='mayorCure8Score']").val();

    var total=0;
    total = parseFloat(total) +parseFloat(location1Score) + parseFloat(meridianScore) + parseFloat(mayorCure1Score);
    if (location2Score != undefined) {
        total = parseFloat(total) +parseFloat(location2Score) ;
    }
    if (location3Score != undefined) {
        total = parseFloat(total) +parseFloat(location3Score) ;
    }
    if (mayorCure2Score != undefined) {
        total = parseFloat(total) +parseFloat(mayorCure2Score) ;
    }
    if (mayorCure3Score != undefined) {
        total = parseFloat(total) + parseFloat(mayorCure3Score);
    }
    if (mayorCure4Score != undefined) {
        total = parseFloat(total) + parseFloat(mayorCure4Score);
    }
    if (mayorCure5Score != undefined) {
        total = parseFloat(total) + parseFloat(mayorCure5Score);
    }
    if (mayorCure6Score != undefined) {
        total = parseFloat(total) + parseFloat(mayorCure6Score);
    }
    if (mayorCure7Score != undefined) {
        total = parseFloat(total) +parseFloat(mayorCure7Score);
    }
    if (mayorCure8Score != undefined) {
        total = parseFloat(total) +parseFloat(mayorCure8Score);
    }
    if (total==totalScore) {
        validateTotalScore = true;
    }
    return validateTotalScore;
}
/*单项手法-儿科手法、成人手法、触诊诊断*/
function  validateIsEqualEachTermAndTotalScoreSinglePloyCEC() {
    debugger
    var validateTotalScore = false;

    var totalScore=$("#form-single-ploy").find("input[name='totalScore']").val();
    var answer1Score=$("#form-single-ploy").find("input[name='answer1Score']").val();
    var answer2Score=$("#form-single-ploy").find("input[name='answer2Score']").val();
    var answer3Score=$("#form-single-ploy").find("input[name='answer3Score']").val();
    var answer4Score=$("#form-single-ploy").find("input[name='answer4Score']").val();
    var answer5Score=$("#form-single-ploy").find("input[name='answer5Score']").val();
    var answer6Score=$("#form-single-ploy").find("input[name='answer6Score']").val();
    var answer7Score=$("#form-single-ploy").find("input[name='answer7Score']").val();
    var answer8Score=$("#form-single-ploy").find("input[name='answer8Score']").val();
    var answer9Score=$("#form-single-ploy").find("input[name='answer9Score']").val();
    var answer10Score=$("#form-single-ploy").find("input[name='answer10Score']").val();

    var total=0;
    total = parseFloat(total) +parseFloat(answer1Score);
    if (answer2Score != undefined) {
        total = parseFloat(total) +parseFloat(answer2Score) ;
    }
    if (answer3Score != undefined) {
        total = parseFloat(total) +parseFloat(answer3Score) ;
    }
    if (answer4Score != undefined) {
        total = parseFloat(total) +parseFloat(answer4Score) ;
    }
    if (answer5Score != undefined) {
        total = parseFloat(total) +parseFloat(answer5Score) ;
    }
    if (answer6Score != undefined) {
        total = parseFloat(total) +parseFloat(answer6Score) ;
    }
    if (answer7Score != undefined) {
        total = parseFloat(total) +parseFloat(answer7Score) ;
    }
    if (answer8Score != undefined) {
        total = parseFloat(total) +parseFloat(answer8Score) ;
    }
    if (answer9Score != undefined) {
        total = parseFloat(total) +parseFloat(answer9Score) ;
    }
    if (answer10Score != undefined) {
        total = parseFloat(total) +parseFloat(answer10Score) ;
    }
    if (total==totalScore) {
        validateTotalScore = true;
    }
    return validateTotalScore;
}
/*成套手法-妇、伤、儿、内科*/
function  validateIsEqualEachTermAndTotalScoreCompletePloyFSEN() {
    var validateTotalScore = false;

    var totalScore=$("#form-complete-ploy").find("input[name='totalScore']").val();
    var answer1Score=$("#form-complete-ploy").find("input[name='answer1Score']").val();
    var answer2Score=$("#form-complete-ploy").find("input[name='answer2Score']").val();
    var answer3Score=$("#form-complete-ploy").find("input[name='answer3Score']").val();
    var answer4Score=$("#form-complete-ploy").find("input[name='answer4Score']").val();
    var answer5Score=$("#form-complete-ploy").find("input[name='answer5Score']").val();
    var answer6Score=$("#form-complete-ploy").find("input[name='answer6Score']").val();
    var answer7Score=$("#form-complete-ploy").find("input[name='answer7Score']").val();
    var answer8Score=$("#form-complete-ploy").find("input[name='answer8Score']").val();
    var answer9Score=$("#form-complete-ploy").find("input[name='answer9Score']").val();
    var answer10Score=$("#form-complete-ploy").find("input[name='answer10Score']").val();
    var answer11Score=$("#form-complete-ploy").find("input[name='answer11Score']").val();
    var answer12Score=$("#form-complete-ploy").find("input[name='answer12Score']").val();
    var answer13Score=$("#form-complete-ploy").find("input[name='answer13Score']").val();
    var answer14Score=$("#form-complete-ploy").find("input[name='answer14Score']").val();
    var answer15Score=$("#form-complete-ploy").find("input[name='answer15Score']").val();
    var answer16Score=$("#form-complete-ploy").find("input[name='answer16Score']").val();
    var answer17Score=$("#form-complete-ploy").find("input[name='answer17Score']").val();
    var answer18Score=$("#form-complete-ploy").find("input[name='answer18Score']").val();
    var answer19Score=$("#form-complete-ploy").find("input[name='answer19Score']").val();
    var answer20Score=$("#form-complete-ploy").find("input[name='answer20Score']").val();
    var answer21Score=$("#form-complete-ploy").find("input[name='answer21Score']").val();
    var answer22Score=$("#form-complete-ploy").find("input[name='answer22Score']").val();
    var answer23Score=$("#form-complete-ploy").find("input[name='answer23Score']").val();
    var answer24Score=$("#form-complete-ploy").find("input[name='answer24Score']").val();
    var answer25Score=$("#form-complete-ploy").find("input[name='answer25Score']").val();
    var answer26Score=$("#form-complete-ploy").find("input[name='answer26Score']").val();
    var answer27Score=$("#form-complete-ploy").find("input[name='answer27Score']").val();
    var answer28Score=$("#form-complete-ploy").find("input[name='answer28Score']").val();
    var answer29Score=$("#form-complete-ploy").find("input[name='answer29Score']").val();
    var answer30Score=$("#form-complete-ploy").find("input[name='answer30Score']").val();


    var total=0;
    total = parseFloat(total) +parseFloat(answer1Score);
    if (answer2Score != undefined) {
        total = parseFloat(total) +parseFloat(answer2Score) ;
    }
    if (answer3Score != undefined) {
        total = parseFloat(total) +parseFloat(answer3Score) ;
    }
    if (answer4Score != undefined) {
        total = parseFloat(total) +parseFloat(answer4Score) ;
    }
    if (answer5Score != undefined) {
        total = parseFloat(total) +parseFloat(answer5Score) ;
    }
    if (answer6Score != undefined) {
        total = parseFloat(total) +parseFloat(answer6Score) ;
    }
    if (answer7Score != undefined) {
        total = parseFloat(total) +parseFloat(answer7Score) ;
    }
    if (answer8Score != undefined) {
        total = parseFloat(total) +parseFloat(answer8Score) ;
    }
    if (answer9Score != undefined) {
        total = parseFloat(total) +parseFloat(answer9Score) ;
    }
    if (answer10Score != undefined) {
        total = parseFloat(total) +parseFloat(answer10Score) ;
    }if (answer11Score != undefined) {
        total = parseFloat(total) +parseFloat(answer11Score) ;
    }if (answer12Score != undefined) {
        total = parseFloat(total) +parseFloat(answer12Score) ;
    }if (answer13Score != undefined) {
        total = parseFloat(total) +parseFloat(answer13Score) ;
    }if (answer14Score != undefined) {
        total = parseFloat(total) +parseFloat(answer14Score) ;
    }if (answer15Score != undefined) {
        total = parseFloat(total) +parseFloat(answer15Score) ;
    }if (answer16Score != undefined) {
        total = parseFloat(total) +parseFloat(answer16Score) ;
    }if (answer17Score != undefined) {
        total = parseFloat(total) +parseFloat(answer17Score) ;
    }if (answer18Score != undefined) {
        total = parseFloat(total) +parseFloat(answer18Score) ;
    }if (answer19Score != undefined) {
        total = parseFloat(total) +parseFloat(answer19Score) ;
    }if (answer20Score != undefined) {
        total = parseFloat(total) +parseFloat(answer20Score) ;
    }if (answer21Score != undefined) {
        total = parseFloat(total) +parseFloat(answer21Score) ;
    }if (answer22Score != undefined) {
        total = parseFloat(total) +parseFloat(answer22Score) ;
    }if (answer23Score != undefined) {
        total = parseFloat(total) +parseFloat(answer23Score) ;
    }if (answer24Score != undefined) {
        total = parseFloat(total) +parseFloat(answer24Score) ;
    }if (answer25Score != undefined) {
        total = parseFloat(total) +parseFloat(answer25Score) ;
    }if (answer26Score != undefined) {
        total = parseFloat(total) +parseFloat(answer26Score) ;
    }if (answer27Score != undefined) {
        total = parseFloat(total) +parseFloat(answer27Score) ;
    }if (answer28Score != undefined) {
        total = parseFloat(total) +parseFloat(answer28Score) ;
    }if (answer29Score != undefined) {
        total = parseFloat(total) +parseFloat(answer29Score) ;
    }if (answer30Score != undefined) {
        total = parseFloat(total) +parseFloat(answer30Score) ;
    }
    if (total==totalScore) {
        validateTotalScore = true;
    }
    return validateTotalScore;
}
/***************************************验证总分与单项和分数是否相等****************************************/

var wendaAcupointLocationCount = 1,wendaAnswerMayorCureCount=1
    ,acupointLocationAdultCount=1,acupointLocationPediatricCount=1,wendaNSFECCount=1,
    singlePloyCECCount=1,completePloyFSENCount=1;
/***************************************每次切换分类将增加次数重置****************************************/
$(document).ready(function () {
    $(".rdobox").click(function(){
        wendaNSFECCount = 1;
        wendaAcupointLocationCount = 1;
        wendaAnswerMayorCureCount = 1;
        acupointLocationAdultCount=1;
        acupointLocationPediatricCount=1;
        singlePloyCECCount = 1;
        completePloyFSENCount = 1;
    });
});
/***************************************每次切换分类将增加次数重置****************************************/

/*============================增加定位、主治或者答案============================================*/
function addTerms(divId,count,msg,category) {
    switch (category) {
        //增加-问答题-腧穴题-定位
        case "wendaAcupointLocation":
            if (wendaAcupointLocationCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                wendaAcupointLocationCount = wendaAcupointLocationCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='location" + wendaAcupointLocationCount + "'placeholder='请输入定位答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='location" + wendaAcupointLocationCount + "Score'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"wendaAcupointLocationCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;
        //增加-问答题-腧穴题-主治
        case "wendaAcupointMayorCure":
            if (wendaAnswerMayorCureCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                wendaAnswerMayorCureCount = wendaAnswerMayorCureCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='mayorCure" + wendaAnswerMayorCureCount + "'placeholder='请输入定位答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='mayorCure" + wendaAnswerMayorCureCount +"Score'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"wendaAnswerMayorCureCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;
        //增加-问答题-腧穴题-NSFEC
        case "wendaNSFEC":
            if (wendaNSFECCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                wendaNSFECCount = wendaNSFECCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='answer" + wendaNSFECCount + "'placeholder='请输入答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='answer" + wendaNSFECCount +"Score'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"wendaNSFECCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
        break;
        //增加-穴位定位-成人穴位-定位
        case "acupointLocationAdultLocation":
            debugger
            if (acupointLocationAdultCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                acupointLocationAdultCount = acupointLocationAdultCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='location" + acupointLocationAdultCount + "Adult'placeholder='请输入定位答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='location" + acupointLocationAdultCount + "ScoreAdult'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"acupointLocationAdultCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;
        //增加-穴位定位-儿科穴位-定位
        case "acupointLocationPediatricLocation":
            debugger
            if (acupointLocationPediatricCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                acupointLocationPediatricCount = acupointLocationPediatricCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='location" + acupointLocationPediatricCount + "Pediatric'placeholder='请输入定位答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='location" + acupointLocationPediatricCount + "ScorePediatric'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"acupointLocationPediatricCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;
        //增加-单项手法-CEC
        case "singlePloyCEC":
            if (singlePloyCECCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                singlePloyCECCount = singlePloyCECCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='answer" + singlePloyCECCount + "'placeholder='请输入答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='answer" + singlePloyCECCount +"Score'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"singlePloyCECCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;
        //增加-成套手法-FSEN
        case "completePloyFSEN":
            if (completePloyFSENCount > count) {
                // 询问框
                layer.confirm(msg, {
                    btn: ["确认"]
                    // 按钮
                });
            } else {
                completePloyFSENCount = completePloyFSENCount + 1;
                var content = "<div class='form-group'><div class='col-sm-2'></div><div class='col-sm-6 display-error'><input type='text' class='form-control' name='answer" + completePloyFSENCount + "'placeholder='请输入答案......'/></div><label class='col-sm-1 control-label' style='padding-left:10px'>分值</label><div class='col-sm-2 display-error'><input type='number' class='form-control' name='answer" + completePloyFSENCount +"Score'/></div><div class='col-md-1'><i onclick='deleteNewAdd(this,\"completePloyFSENCount\")' class='glyphicon glyphicon-remove' style='margin-left: 80%;margin-top:12%;cursor: pointer;'></i></div></div>";
                $(divId).append(content);
            }
            break;

        default:
        // ...
    }
}
/*============================增加定位、主治或者答案============================================*/

/**************************************************************删除新增项****************************************************/
function deleteNewAdd(obj, countName) {
    $(obj).parent().parent().remove();
    switch (countName) {
        case "wendaAcupointLocationCount":
            wendaAcupointLocationCount = wendaAcupointLocationCount - 1;
            break;
        case "wendaAnswerMayorCureCount":
            wendaAnswerMayorCureCount = wendaAnswerMayorCureCount - 1;
            break;
        case "wendaNSFECCount":
            wendaNSFECCount = wendaNSFECCount - 1;
        case "acupointLocationAdultCount":
            acupointLocationAdultCount = acupointLocationAdultCount - 1;
            break;
        case "acupointLocationPediatricCount":
            acupointLocationPediatricCount = acupointLocationPediatricCount - 1;
        case "singlePloyCECCount":
            singlePloyCECCount = singlePloyCECCount - 1;
            break;
        case "completePloyFSENCount":
            completePloyFSENCount = completePloyFSENCount - 1;
            break;
        default:
    }
}
/**************************************************************删除新增项****************************************************/
function getTime() {
    var dateObj = new Date();
    var year = dateObj.getFullYear();//年
    var month = dateObj.getMonth() + 1;//月  (注意：月份+1)
    var date = dateObj.getDate();//日
    var day = dateObj.getDay();
    var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    var week = weeks[day];//根据day值，获取星期数组中的星期数。
    var hours = dateObj.getHours();//小时
    var minutes = dateObj.getMinutes();//分钟
    var seconds = dateObj.getSeconds();//秒

    if (month < 10) {
        month = "0" + month;
    }
    if (date < 10) {
        date = "0" + date;
    }
    if (hours < 10) {
        hours = "0" + hours;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (seconds < 10) {
        seconds = "0" + seconds;
    }

    var newDate = year + "年" + month + "月" + date + "日" + "(" + week + ")" + "&nbsp;&nbsp" + hours + ":" + minutes + ":" + seconds;
    document.getElementById("date-time").innerHTML = newDate;//在div中写入时间
    setTimeout('getTime()', 500);//每隔500ms执行一次getTime()
}